-- 
-- SpecType 技能专精
-- 

local SpecType = class("SpecType")

function SpecType:ctor(id, db)
    self.id=tonumber(id) or 0
    self.isNew=false
    self.isLocked=false
    self._isActive = false
    if self.id>0 then
        self:read(self.id, db)
    end
end

function SpecType:isValid()
    return self.db~=nil
end

function SpecType:read(id, db)
    self.id = tonumber(id)
    self.db = db or GD:getSpec_typeConfig(self.id)

    self._icon = nil
    self._featureIcon = nil
    self._generalSkillTeam = nil -- 通用技能组
    self._changeSkillTeams = nil -- 专精可以替换的技能组
    self._defaultSkillTeams = nil -- 专精默认的技能组
end

function SpecType:getId()
    return self.id
end

function SpecType:setActive(b)
    self._isActive = b
end

function SpecType:isActive()
    return self._isActive
end

function SpecType:getUnlockLevel()
    return tonumber(self.db.unlockLevel) or 0
end

function SpecType:getNameDes()
    return L(self.db.nameDes)
end

function SpecType:getIcon()
    if not self._icon then
        self._icon = table.concat({Res.SpecTypeIconPath, self.db.jobType, ".png"})
    end
    return self._icon
end

function SpecType:getFeatureDes()
    return L(self.db.featureDes)
end

function SpecType:getFeatureIcon()
    if not self._featureIcon then
        return table.concat({Res.battleBuffIconPath, self.db.featureIcon, ".png"})
    end
    return self._featureIcon
end

function SpecType:getDuty()
    return L(self.db.dutyDes)
end

function SpecType:getShowDutyDes()
    if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_TIPS_CRYSTAL_LVUP) then
        return L("master"..self.db.master)
    else
        return self:getDutyDes()
    end
end

function SpecType:getDutyDes()
    return L("dutydesc"..self.db.dutyDes)
end

function SpecType:setIsNewGet(isNew)
	self.isNew = isNew
end

function SpecType:isOpen()
	return UD:getLevel()>=self:getUnlockLevel()
end

function SpecType:_initSpecSkillTeam()
    if not self._generalSkillTeam then
        local conf = GD:getSpecSkillChoose(self.id)
        local skillTeams = table.tonumber(string.split(conf.skillChange, ";"))
        self._changeSkillTeams = skillTeams
        self._generalSkillTeam = tonumber(conf.universalSkill)

        skillTeams = {}
        for i=1,5 do
            local skillSlot = conf["skillSlot" .. i]
            local foundIdx = string.find(skillSlot, ";")
            if foundIdx then
                skillSlot = string.sub(skillSlot, 1, foundIdx-1)
            end
            skillTeams[#skillTeams + 1] = tonumber(skillSlot)
        end
        self._detaultSkillTeams = skillTeams
    end
end

-- 获取通用技能组Id
function SpecType:getGeneralSkillTeam()
    self:_initSpecSkillTeam()
    return self._generalSkillTeam
end

-- 获取可替换技能组Ids
function SpecType:getDefaultSkillTeams()
    self:_initSpecSkillTeam()
    return self._detaultSkillTeams
end

-- 获取可替换技能组Ids
function SpecType:getChangeSkillTeams()
    self:_initSpecSkillTeam()
    return self._changeSkillTeams
end

-- 存储和角色扮演相关的参数
function SpecType:setRoleExtraParams(dutyShow, roleName)
    self._dutyShow = dutyShow
    self._roleName = roleName
end
function SpecType:getRoleExtraParams()
    return self._dutyShow, self._roleName
end

return SpecType
